package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.WaterWorkOrder;
import com.ruoyi.system.mapper.WaterWorkOrderMapper;
import com.ruoyi.system.service.IWaterWorkOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 工单Service业务层处理
 *
 * @author ruoyi
 * @date 2025-09-16
 */
@Service
public class WaterWorkOrderServiceImpl implements IWaterWorkOrderService
{
    @Autowired
    private WaterWorkOrderMapper waterWorkOrderMapper;

    /**
     * 查询工单
     *
     * @param orderId 工单主键
     * @return 工单
     */
    @Override
    public WaterWorkOrder selectWaterWorkOrderByOrderId(Long orderId)
    {
        return waterWorkOrderMapper.selectWaterWorkOrderByOrderId(orderId);
    }

    /**
     * 查询工单列表
     *
     * @param waterWorkOrder 工单
     * @return 工单
     */
    @Override
    public List<WaterWorkOrder> selectWaterWorkOrderList(WaterWorkOrder waterWorkOrder)
    {
        return waterWorkOrderMapper.selectWaterWorkOrderList(waterWorkOrder);
    }

    /**
     * 新增工单
     *
     * @param waterWorkOrder 工单
     * @return 结果
     */
    @Override
    public int insertWaterWorkOrder(WaterWorkOrder waterWorkOrder)
    {
        return waterWorkOrderMapper.insertWaterWorkOrder(waterWorkOrder);
    }

    /**
     * 修改工单
     *
     * @param waterWorkOrder 工单
     * @return 结果
     */
    @Override
    public int updateWaterWorkOrder(WaterWorkOrder waterWorkOrder)
    {
        return waterWorkOrderMapper.updateWaterWorkOrder(waterWorkOrder);
    }

    @Override
    public int updateWaterWorkOrderNumber(WaterWorkOrder waterWorkOrder)
    {
        return waterWorkOrderMapper.updateWaterWorkOrderNumber(waterWorkOrder);
    }

    /**
     * 批量删除工单
     *
     * @param orderIds 需要删除的工单主键
     * @return 结果
     */
    @Override
    public int deleteWaterWorkOrderByOrderIds(Long[] orderIds)
    {
        return waterWorkOrderMapper.deleteWaterWorkOrderByOrderIds(orderIds);
    }

    /**
     * 删除工单信息
     *
     * @param orderId 工单主键
     * @return 结果
     */
    @Override
    public int deleteWaterWorkOrderByOrderId(Long orderId)
    {
        return waterWorkOrderMapper.deleteWaterWorkOrderByOrderId(orderId);
    }


    @Override
    public String getMaxOrderNumber() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String timestamp = sdf.format(new Date());
        int randomNum = (int) (Math.random() * 900) + 100; // 100-999的随机数
        return timestamp + randomNum;
    }

}
